﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.Dto.ProSorce;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.FarmingInformation
{
    public class BreedingcompanyphotoCreateHander : IRequestHandler<BreedingcompanyphotoCreateCommond, Rulst>
    {
        /// <summary>
        /// 养殖信息管理
        /// </summary>
        private readonly IbaseRpository<breedMess> _breedMess;
        /// <summary>
        /// 放置图片
        /// </summary>
        private readonly IbaseRpository<ProductionPutImages> _ProdctionPutimges;
        /// <summary>
        /// 保健信息
        /// </summary>
        private readonly IbaseRpository<VaccineMess> _Vacciont;

        public BreedingcompanyphotoCreateHander(IbaseRpository<breedMess> breedMess, IbaseRpository<ProductionPutImages> _ProdctionPutimges, IbaseRpository<VaccineMess> vacciont)
        {
            _breedMess = breedMess;
            this._ProdctionPutimges = _ProdctionPutimges;
            _Vacciont = vacciont;
        }

        public async Task<Rulst> Handle(BreedingcompanyphotoCreateCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };



            var listfrom = (from a in _breedMess.Query()
                            where a.ProDuctionBasicid == request.ProDuctionBasicid
                            select new BreedingcompanyphotoCreateDto()
                            {
                                Startinspection = new List<Startinspection>(),
                                Breedcome = a.Breedcome,
                                BreedDay = a.BreedDay,
                                Breedingenterprise = new List<Breedingenterprise>(),
                                ColumnTime = a.ColumnTime,
                                Farm = a.Farm,
                                FarmName = a.FarmName,
                                Fodderbrand = a.Fodderbrand,
                                FodderName = a.FodderName,
                                Framnum = a.Framnum,
                                ProDuctionBasicid = a.ProDuctionBasicid,
                                Vaccineid = a.Vaccineid,
                                varietyName = a.varietyName,
                                Vaccione = new List<Vaccione>()
                            }).FirstOrDefault();
            if (listfrom != null)
            {
                var gh = _Vacciont.Query().Where(x => x.ProDuctionBasicid == request.ProDuctionBasicid).Select(x => new Vaccione
                {
                    HealthcareMethod = x.HealthcareMethod,
                    HealThcareMode = x.HealThcareMode,
                    RearDay = x.RearDay,
                    VaccioneMessid = x.VaccioneMessid,
                   
                }).ToList();

                if (gh != null)
                {
                    listfrom.Vaccione = gh;
                }

                var getone = _ProdctionPutimges.Query().Where(x => x.ProDuctionBasicid == listfrom.ProDuctionBasicid && x.Stypeid == Typenum.动检证).Select(x => new Startinspection
                {
                    getimages = x.PutImages
                }).ToList();

                if (getone != null)
                {
                    listfrom.Startinspection = getone;
                }




                var gettwo = _ProdctionPutimges.Query().Where(x => x.ProDuctionBasicid == listfrom.ProDuctionBasicid && x.Stypeid == Typenum.企业照片).Select(x => new Breedingenterprise
                {
                    getimagest = x.PutImages
                }).ToList();

                if (gettwo != null)
                {
                    listfrom.Breedingenterprise = gettwo;
                }

            }
            else
            {
                listfrom=new BreedingcompanyphotoCreateDto();



            }
            query.data = listfrom;
            return query;



        }
    }
}
